﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Areas/Commerce/Views/Shared/Backend.Master" Inherits="System.Web.Mvc.ViewPage<Kooboo.Commerce.Order>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    <%:"Index".Localize() %>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <%: Html.Partial("OrderProgress", Kooboo.Commerce.OrderStatus.ShoppingCart)%>

        <div class="shopping">
        <h3>
            <%: "Shopping Cart".Localize() %></h3>
        <div class="order-summary table-wrapper">
            <% using (Html.BeginForm("DeleteOrderItem", "Cart"))
               {%>
            <table>
                <thead>
                    <tr>
                        <th><%: "Picture".Localize()%></th>
                        <th><%: "Product".Localize()%></th>
                        <th><%: "Unit Price".Localize()%></th>
                        <th><%: "Quantity".Localize()%></th>
                        <th><%: "SubTotal".Localize()%></th>
                        <th><%: "Discount".Localize()%></th>
                        <th><%: "TaxCost".Localize()%></th>
                        <th><%: "Total".Localize()%></th>
                        <th><%: "Delete".Localize()%></th>
                    </tr>
                </thead>
                <tbody>
                    <% 
         
                foreach (var orderItem in this.Model.Items)
                {
                    %>
                    <tr id='orderitem<%: orderItem.Id %>' <% if (orderItem.Status == OrderItemStatus.ZeroStock){%>class="unavailable"<%} %> >
                        <td class="image">
                            <img alt="<%: orderItem.ProductName %>" width="75" height="75" 
                            src='<%: orderItem.ImageUrl %>' />
                        </td>
                        <td class="title">
                            <a href='<%: orderItem.TitleUrl %>' target="_blank">
                                <%: orderItem.ProductName%>
                            </a>
                            <span class="choice"><%: orderItem.SerializedAttributeValues%></span>
                            <span class="error">
                                <% if (orderItem.Status == OrderItemStatus.ZeroStock)
                                   {%>
                                    <%: "product sold out".Localize()%>
                                <%} %>
                            </span>
                        </td>
                        <td class="unit-price">
                            <%: orderItem.UnitPrice.ToString("c")%>
                        </td>
                        <td class="quantity">
                            <input type="text" value='<%: orderItem.Quantity %>'
                             name='quantity' class="mini-input-text"
                             <% if (orderItem.Status == OrderItemStatus.ZeroStock){ %> disabled="disabled"<%} %>
                                stock='<%: orderItem.Stock %>' />
                            <span class="error">
                                <% if (orderItem.Status == OrderItemStatus.OutOfStock)
                                   { %>
                                    <%: "out of stock ".Localize() + orderItem.Stock%>
                                <% } %>
                            </span>
                        </td>
                        <td class="subtotal">
                            <%: orderItem.SubTotal.ToString("c")%>
                        </td>
                        <td class="discount">
                            <%: orderItem.Discount.ToString("c")%>
                        </td>

                        <td>
                            <%: orderItem.TaxCost.ToString("c")%>
                        </td>

                        <td class="total">
                            <%: orderItem.Total.ToString("c")%>
                        </td>
                   
                        <td>
                            <input type="submit" class="delete" name="id" value="<%: orderItem.Id %>" />
                        </td>
                    </tr>
                    <%} %>
                </tbody>
                <tfoot>
                    <tr>
                        <td colspan="8" class="title">
                            <%:"Order Discount".Localize()%>
                        </td>
                        <td>
                            <strong>
                                <%: Model.OrderDiscount.ToString("c")%>
                            </strong>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="8" class="title">
                            <%:"SubTotal".Localize()%>
                        </td>
                        <td>
                            <strong>
                                <%: Model.SubTotal.ToString("c")%>
                            </strong>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="8" class="title">
                            <%:"Total Discount".Localize()%>
                        </td>
                        <td>
                            <strong>
                                <%: Model.TotalDiscount.ToString("c")%>
                             </strong>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="8" class="title">
                            <%:"Total Tax Cost".Localize()%>
                        </td>
                        <td>
                            <strong>
                                <%: this.Model.TotalTaxCost.ToString("c")%>
                            </strong>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="8" class="title">
                            <%:"ShippingCost".Localize()%>
                        </td>
                        <td>
                            <strong>
                                <%: Model.ShippingCost.ToString("c")%>
                            </strong>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="8" class="title">
                            <%:"PaymentMethodCost".Localize()%>
                        </td>
                        <td>
                            <strong>
                                <%: Model.PaymentMethodCost.ToString("c")%>
                            </strong>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="8" class="title">
                            <%:"Total".Localize()%>
                        </td>
                        <td>
                            <strong>
                                <%: Model.Total.ToString("c")%>
                            </strong>
                        </td>
                    </tr>
                </tfoot>
            </table>
            <%} %>
        </div>
        <% using (Html.BeginForm())
           { %>
        <div class="shopping-goto">
            <div class="next-step">
                <input type="submit" name="shoppingAddress" value='<%: "Next".Localize() %>'  />
            </div>
        </div>
        <%} %>
    </div>

    <form name="update-quantity-form" method="post" action="/Commerce/Cart/UpdateQuantity">
        <input type="hidden" name="itemId"/>
        <input type="hidden" name="quantity" />
    </form>
    
    <script type="text/javascript">
        $(document).ready(function () {

            // change quantity
            $('.order-summary input[name=quantity]').change(function () {

                var tr = $(this).parents('tr:eq(0)');
                var unitPrice = tr.find('.unit-price').text();
                var quantity = $(this).val();
                var itemId = tr.attr('id').replace('orderitem', '');
                var stock = parseInt($(this).attr('stock'));

                if (isNaN(quantity) || quantity < 1) {
                    $(this).val(1);

                    return;
                }

                if (quantity > stock) {
                    $(this).siblings('.error')
                        .text('<%: "out of stock ".Localize() %>' + stock);

                    return;
                }

                $(this).siblings('.error').empty();

                $.blockUI({
                    message: '<h3><img src="/Areas/Commerce/Content/images/ajax_loading.gif" /> <%:"Just a moment...".Localize() %></h3>',
                    css: {
                        border: 'none',
                        padding: '15px',
                        backgroundColor: '#000',
                        '-webkit-border-radius': '10px',
                        '-moz-border-radius': '10px',
                        opacity: .5,
                        color: '#fff',
                        cursor: 'default'
                    }
                });

                $('form[name=update-quantity-form] input[name=itemId]').val(itemId);
                $('form[name=update-quantity-form] input[name=quantity]').val(quantity);
                $('form[name=update-quantity-form]').submit();
            });
        });
    </script>
</asp:Content>

